package dome.cachedome.controller;

import dome.cachedome.User;
import dome.cachedome.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @className: UserController
 * @description: TODO 类描述
 * @author: Jp
 * @date: 2022/9/9
 **/
@RestController
public class UserController {

    @Autowired private UserService userService;

    /**
     *
     * 通过用户id查询用户缓存
     *
     *
     * @date: 2022/9/9
     */
    @GetMapping(value = "/v1/api/findByUser/{userId}")
    public User findUserById(@PathVariable("userId") String userId){

        // 可以自定义缓存失效时间 ， 不定义的话默认一天
        //new User(userId).getObjectVo(3000,()->userService.findUserById(userId));

        return new User(userId).getObjectVo(()->userService.findUserById(userId));
    }

    /**
     *
     * 删除用户缓存方法的dome调用
     *
     *
     * @date: 2022/9/9
     */
    @DeleteMapping(value = "/v1/api/delete/{userId}")
    public void deleteUserCache(@PathVariable("userId") String userId){
        new User(userId).deleteCache();
    }

}
